<?php
/**
 * @Author: your name
 * @Date:   2017-05-25 14:31:26
 * @Last Modified by:   your name
 * @Last Modified time: 2017-05-27 16:55:35
 */
namespace app\index\controller;
use app\index\controller\Home;
class News extends Home
{

    public function _initialize()
    {
        parent::_initialize();
        $this->uid = session('wx_uid');
    }

    public function saveComment()
    {
        $pid = input('post.pid');
        $comment = input('post.comment');
        if(empty($pid)){
            return json(['code'=>0,'message'=>'没有此贴--']);
        }
        if(empty($comment)){
            return json(['code'=>0,'message'=>'评论内容不能为空']);
        }
        $data['content'] = input('post.comment');
        $data['pid'] = input('post.pid');
        $data['create_time'] = time();
        $data['uid'] = $this->uid;
        $data['status'] = 1;
        $id = db('comment')->insertGetId($data);
        if($id){
            return json(['code'=>$id,'message'=>'评论成功']);
        }else{
            return json(['code'=>0,'message'=>'评论失败']);
        }
    }
}